home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / dev / lang / HeliOS3.lha / helios_demo_disk3 / source / Demo2_SinglePFCopper.src < prev    next >
Encoding:
Text File  |  1995-11-11  |  13.8 KB  |  496 lines

  1.  
  2.   \ **********************************************************
  3.   \
  4.   \       SINGLE PLAYFIELD WITH USER COPPERLIST DEMO
  5.   \
  6.   \ **********************************************************
  7.   \
  8.   \ This code demonstrates how to create a single playfield
  9.   \ display with a user copperlist displaying colour bars.
  10.   \
  11.   \ This code builds upon the following Demos:
  12.   \
  13.   \ Demo1_SinglePF.src
  14.   \
  15.   \ This code is then expanded in the following Demos:
  16.   \
  17.   \ Demo3_SimpleSprite.src
  18.   \ Demo4_MultiSprites.src
  19.   \ Demo5_MultiSptCollide.src
  20.   \ Demo6_SimpleAnim.src
  21.   \ Demo7_MultiAnim.src
  22.   \
  23.   \ ***********************************************************
  24.  
  25.  
  26.  
  27.   \ ***********************************************************
  28.   \ Re-initialise HeliOS dictionary to standard CORE vocabulary
  29.   \ ***********************************************************
  30.  
  31.   \ This should always be used at the start of any program which
  32.   \ is to be repeatedly recompiled.
  33.  
  34.   FORGET **CORE**
  35.  
  36.   \ *************************
  37.   \ Load include symbol files
  38.   \ *************************
  39.   \
  40.   \ These "include files" are pre-compiled (for speed) versions of the
  41.   \ Amiga includes and the Helios system includes.
  42.   \
  43.   \ Uncomment the lines below for standalone compilation, but otherwise
  44.   \ it is better to set these include files from the Helios Forth menus
  45.  
  46.   AMIGAINCLUDE HeliOS:HeliOS_AmigaInclude
  47.   USERINCLUDE  HeliOS:HeliOS_UserInclude
  48.  
  49.   \ ****************************************
  50.   \ Create display imagery file name strings
  51.   \ ****************************************
  52.  
  53.   \ These files are ordinary IFF's (and may be "PowerPacked" if required)
  54.   \
  55.   \ The pictures here will be loaded into each of the display BitMaps.
  56.   \
  57.  
  58.   $CONSTANTL Slice1Pic $Helios:Source/Data/Pic2$
  59.  
  60.   \ **************************************
  61.   \ Create display configuration constants
  62.   \ **************************************
  63.   \
  64.   \ Collect all "display-specific" parameters here and generate "named"
  65.   \ constants which make references easier than using numeric values.
  66.   \
  67.   \ Collecting these together here makes it easier to adjust things at any
  68.   \ time without having to search source code to replace values individually.
  69.   \
  70.  
  71.  
  72.   256                      CONSTANT DisplayHeight      \ Full PAL display
  73.   320                      CONSTANT DisplayWidth       \ Lores display
  74.   44                       CONSTANT DisplayTopLine     \ Display start
  75.  
  76.   DisplayWidth             CONSTANT Slice1Width        \ Lores width
  77.   DisplayWidth 32 +        CONSTANT Slice1RasterWidth  \ Raster=SWidth+32
  78.   DisplayHeight            CONSTANT Slice1Height       \ Slice height
  79.   DisplayHeight 32 +       CONSTANT Slice1RasterHeight \ Slice Raster=DHgt+32
  80.   0                        CONSTANT Slice1Mode         \ Lores
  81.   3                        CONSTANT Slice1Planes       \ Slice bitplanes
  82.  
  83.   \ The calculation below takes the number of bitplanes and calculates
  84.   \ how many colours this represents.
  85.   \
  86.   \ One bitplane gives two colours.
  87.   \
  88.   \ Each additional bitplane multiplies the number of colours by two.
  89.   \
  90.   \ Performing a single LSL operation on any number multipies by 2, so we
  91.   \ have a quick method of multiplying by two for our colour calculation.
  92.   \
  93.   \ In this case, we need "2 to the power 3", which is 2*2*2=8.
  94.   \
  95.   \ e.g.                              2*2*2
  96.   \                                   ^ ^ ^
  97.   \                                   Total number of planes = 3
  98.   \
  99.   \
  100.   \ So, we take the first value two
  101.   \
  102.   \ e.g.                              2*2*2
  103.   \                                   ^
  104.   \                                  Initial start value of 2
  105.   \
  106.   \ and we now need to multiply it by two "the_number_of_planes minus_one"
  107.   \ more times.
  108.   \
  109.   \ e.g.                              2*2*2
  110.   \                                     ^ ^
  111.   \                                     Total planes minus one
  112.   \
  113.   \
  114.   \ So, Number of colours = 2 operated on by LSL NumberOfPlanes-1 times.
  115.   \
  116.  
  117.   2 Slice1Planes 1- LSL    CONSTANT Slice1Colours      \ A-slice colours
  118.  
  119.   \ ***********************
  120.   \ Error handling routines
  121.   \ ***********************
  122.  
  123.   \ This error handler allows all errors to be routed via a comprehensive
  124.   \ sequential closedown routine, which is associated with the HeliOS
  125.   \ system error handler word ERROR".
  126.   \
  127.   \ When ERROR" senses an error, it prints an associated error message
  128.   \ delimited by '"' characters, and then closes everything down using the
  129.   \ routine CLOSEDOWN below which you have supplied.
  130.   \
  131.   \ This simplifies errors checks to the use of a single word, ERROR", which
  132.   \ displays a text message and closes eveything down.
  133.   \
  134.  
  135.   0 VARIABLE (CLOSEDOWN)
  136.  
  137.   : ?CLOSEDOWNERROR
  138.  
  139.   IF
  140.     CR
  141.     CR
  142.     TYPE
  143.     CR
  144.     CR
  145.     ." Press <Space> to quit!"
  146.     CR
  147.     CR
  148.     WAITSPACE
  149.     (CLOSEDOWN) @EXECUTE
  150.     QUIT
  151.   ELSE
  152.     DDROP
  153.   THEN
  154.   ;
  155.  
  156.   LATESTCFA VARIABLE ERROR1
  157.  
  158.   \ ****************************************
  159.   \ Create display pointer storage variables
  160.   \ ****************************************
  161.  
  162.   \ Here we create a set of "pointers", initially set to a "null" value.
  163.   \
  164.   \ These "pointers" are set up as "long addresses" when various components
  165.   \ of the display system are allocated and initialised.
  166.   \
  167.   \ Note that initially these are all set to zero, and we clear them back
  168.   \ to zero when we de-allocate the associated resource.
  169.   \
  170.   \ These DPOINTERs are all initially set to "null" by using '0.'.
  171.   \
  172.   \ When we allocate memory or Amiga system resources in the program at
  173.   \ run-time, these pointers are updated to contain the 32-bit address
  174.   \ of the newly allocated resource.
  175.   \
  176.   \ Subsequently the symbolic DPOINTER name can be used in your code to
  177.   \ represent the associated address.
  178.  
  179.   0. DPOINTER Display1             \ Main Display structure pointer
  180.   0. DPOINTER Slice1               \ Slice 1 Slice structure pointer
  181.  
  182.   0. DPOINTER Slice1_ColorMap      \ Slice 1 ColourMap structure pointer
  183.  
  184.   0. DPOINTER Slice1_RasInfo       \ Slice 1 RasInfo structure pointer
  185.  
  186.   0. DPOINTER Slice1_BMap          \ Slice 1 BitMap structure pointer
  187.  
  188.   0. DPOINTER Slice1_SliceControl  \ Slice 1 SliceControl structure pointer
  189.  
  190.   \ *************
  191.   \ Colour tables
  192.   \ *************
  193.  
  194.   \ Each colour entry requies 2 bytes of storage space
  195.  
  196.   CREATEL Slice1_ColorTable        \ Create longword pointer to table
  197.   Slice1Colours 2* 0 ALLOTFILL     \ Allocate Slice1 colours * 2 bytes
  198.  
  199.  
  200.   \ *************************************
  201.   \ Copper strip for graduated background
  202.   \ *************************************
  203.  
  204.   0. DVARIABLE Copper              \ 32-bit CopperList pointer store
  205.   0. DVARIABLE CopperLength        \ 32-bit CopperList length store
  206.  
  207.   : AddCopper                      \ Add custom copper list to display
  208.  
  209.   Display1                         \ We are adding CopperList to Display1
  210.   Copper D@
  211.   ADDCOPPERSTRIP
  212.   SORTSTRIPTABLE
  213.   LINKSTRIPS
  214.   DDROP
  215.   ;
  216.  
  217.   : RemCopper                      \ Remove custom copper list from display
  218.  
  219.   Display1                         \ We are removing CopperList from Display1
  220.   Copper D@
  221.   DFLAG
  222.   IF
  223.     REMCOPPERSTRIP
  224.     LINKSTRIPS
  225.     DDROP
  226.   ELSE
  227.     DDDROP
  228.   THEN
  229.   ;
  230.  
  231.   : Create_Copper
  232.  
  233.   COPPERSTART
  234.   Copper D!
  235.   0 [ DECIMAL ]  45 [ HEX ] FFFE COPPERWAIT  DROP   0100 18E COPPERMOVE  DROP
  236.   0 [ DECIMAL ]  60 [ HEX ] FFFE COPPERWAIT  DROP   0200 18E COPPERMOVE  DROP
  237.   0 [ DECIMAL ]  75 [ HEX ] FFFE COPPERWAIT  DROP   0300 18E COPPERMOVE  DROP
  238.   0 [ DECIMAL ]  90 [ HEX ] FFFE COPPERWAIT  DROP   0400 18E COPPERMOVE  DROP
  239.   0 [ DECIMAL ] 105 [ HEX ] FFFE COPPERWAIT  DROP   0500 18E COPPERMOVE  DROP
  240.   0 [ DECIMAL ] 120 [ HEX ] FFFE COPPERWAIT  DROP   0600 18E COPPERMOVE  DROP
  241.   0 [ DECIMAL ] 135 [ HEX ] FFFE COPPERWAIT  DROP   0700 18E COPPERMOVE  DROP
  242.   0 [ DECIMAL ] 150 [ HEX ] FFFE COPPERWAIT  DROP   0800 18E COPPERMOVE  DROP
  243.   0 [ DECIMAL ] 165 [ HEX ] FFFE COPPERWAIT  DROP   0900 18E COPPERMOVE  DROP
  244.   0 [ DECIMAL ] 180 [ HEX ] FFFE COPPERWAIT  DROP   0A00 18E COPPERMOVE  DROP
  245.   0 [ DECIMAL ] 195 [ HEX ] FFFE COPPERWAIT  DROP   0B00 18E COPPERMOVE  DROP
  246.   0 [ DECIMAL ] 210 [ HEX ] FFFE COPPERWAIT  DROP   0C00 18E COPPERMOVE  DROP
  247.   0 [ DECIMAL ] 225 [ HEX ] FFFE COPPERWAIT  DROP   0D00 18E COPPERMOVE  DROP
  248.   0 [ DECIMAL ] 240 [ HEX ] FFFE COPPERWAIT  DROP   0E00 18E COPPERMOVE  DROP
  249.   0 [ DECIMAL ] 255 [ HEX ] FFFE COPPERWAIT  DROP   0F00 18E COPPERMOVE  DROP
  250.   [ DECIMAL ]
  251.   COPPEREND
  252.   CopperLength D!   Copper D!
  253.   ADDCOPPER
  254.   ;
  255.  
  256.   : Free_Copper                  \ Closes down and frees copperlist memory
  257.  
  258.   RemCopper
  259.   Copper D@ FREEMEMORY
  260.   ;
  261.  
  262.   \ ***********************************
  263.   \ Create Display and Slice structures
  264.   \ ***********************************
  265.  
  266.   \ This routine simply makes blank structures, which then need to be
  267.   \ initialised later (in the CREATE_DISPLAY routine).
  268.  
  269.   : CREATE_DSLICES
  270.  
  271.   DS_SIZEOF MAKESTRUCTURE Display1 MAKEPOINTER  \ Main "Display" structure
  272.  
  273.   SL_SIZEOF MAKESTRUCTURE Slice1   MAKEPOINTER  \ Display "Slice" structure
  274.   ;
  275.  
  276.   : FREE_DSLICES
  277.  
  278.   Slice1    DDUP FREEMEMORY   CLEARPOINTER
  279.   Display1  DDUP FREEMEMORY   CLEARPOINTER
  280.   ;
  281.  
  282.   \ ******************************
  283.   \ Create RasInfo structures etc.
  284.   \ ******************************
  285.  
  286.   : CREATE_RASINFO
  287.  
  288.   \ First allocate and initialise complete RasInfo structures.
  289.   \
  290.   \ This routine automatically allocates all BitMaps etc.
  291.   \
  292.  
  293.   Slice1RasterWidth Slice1RasterHeight Slice1Planes  OPENRASINFO
  294.   DFLAG0= ERROR" Fail: RasInfo1"
  295.   Slice1_RasInfo MAKEPOINTER
  296.  
  297.   \ Set invisible area "sprite margins" for slice RasInfo
  298.  
  299.   16              Slice1_RasInfo         ri_RxOffset    INDEX!L
  300.   16              Slice1_RasInfo         ri_RyOffset    INDEX!L
  301.  
  302.   \ Store BitMap pointer - often useful for later reference
  303.  
  304.   Slice1_RasInfo  ri_BitMap INDEXD@L Slice1_BMap MAKEPOINTER
  305.   ;
  306.  
  307.   : FREE_RASINFO
  308.  
  309.   Slice1_RasInfo   DDUP CLOSERASINFO   CLEARPOINTER
  310.   ;
  311.  
  312.   \ ********************************
  313.   \ Create Display/Slice Copperlists
  314.   \ ********************************
  315.  
  316.   \ This function builds the main display copperlist by:
  317.   \
  318.   \ 1. Initialising the Slice data structure
  319.   \ 2. Calling MAKECOPSTRIP for the slice, to build a copperlist
  320.   \ 3. Calling MAKEDISPLAY to build the master Display copperlist
  321.   \
  322.  
  323.   : CREATE_DISPLAY
  324.  
  325.   \ First initialise main display structures
  326.  
  327.   Slice1                           Display1  DS_Slice     INDEXD!L
  328.  
  329.   Slice1Width                      Slice1    SL_DWidth    INDEX!L
  330.   Slice1Height                     Slice1    SL_DHeight   INDEX!L
  331.   DisplayTopLine                   Slice1    SL_DyOffset  INDEX!L
  332.   Slice1_RasInfo                   Slice1    SL_RasInfo   INDEXD!L
  333.   Slice1_ColorMap                  Slice1    SL_ColorMap  INDEXD!L
  334.   Slice1Mode                       Slice1    SL_Modes     INDEX!L
  335.  
  336.   \ Generate copper list information for each of the display slices
  337.  
  338.   Slice1 MAKECOPSTRIP
  339.   D0= ERROR" Fail: Slice1CopStrip"
  340.  
  341.   \ Make display
  342.  
  343.   Display1 MAKEDISPLAY
  344.   D0= ERROR" Fail: Display1"
  345.   ;
  346.  
  347.   : FREE_DISPLAY
  348.  
  349.   Display1                 FREEDISPLAY
  350.   Slice1                   FREECOPSTRIP
  351.   ;
  352.  
  353.   \ ********************************************************
  354.   \ Create SliceControl structures for double buffered slice
  355.   \ ********************************************************
  356.  
  357.   \ SliceControl structures are used to control any slices which perform
  358.   \ mapping or scrolling functions, or which require double or triple
  359.   \ playfield buffering.
  360.   \
  361.   \ In this case we have one slice which does not scroll, is not mapped,
  362.   \ but IS double buffered.
  363.   \
  364.  
  365.   : CREATE_SLICECONTROL
  366.  
  367.   \ Make SliceControl for double buffered bitmap display
  368.  
  369.   Slice1  0 0 MAKESLICECONTROL
  370.   DFLAG0= ERROR" Fail: SliceControl1"
  371.   Slice1_SliceControl MAKEPOINTER
  372.  
  373.   \ Install slice controls into HeliOS display control system
  374.  
  375.   Slice1_SliceControl  INSTALLSLICECONTROL
  376.   ;
  377.  
  378.   : FREE_SLICECONTROL
  379.  
  380.   CLEARSLICECONTROLS
  381.   Slice1_SliceControl  CLOSESLICECONTROL
  382.   ;
  383.  
  384.   \ These routines load an IFF picture into supplied BitMap, and correctly
  385.   \ initialises the supplied ColorTable.
  386.   \
  387.   \ The ColorTable is then used to create an initialised ColorMap structure.
  388.   \
  389.  
  390.   : CREATE_IMAGERY
  391.  
  392.   Slice1_BMap
  393.   Slice1_ColorTable
  394.   Slice1Pic
  395.   10 2 DOSLIB                        \ Call to internal HeliOS library
  396.   10 <> ERROR" Fail: Slice1Pic"
  397.  
  398.   Slice1_ColorTable  Slice1Colours MAKECOLORMAP  \ Allocate ColourMap
  399.   DFLAG0= ERROR" Fail: Slice1ColorMap"
  400.   Slice1_ColorMap MAKEPOINTER
  401.   ;
  402.  
  403.   : FREE_IMAGERY
  404.  
  405.   Slice1_ColorMap  DDUP FREECOLORMAP  CLEARPOINTER
  406.   ;
  407.  
  408.   \ *********************
  409.   \ Close down everything
  410.   \ *********************
  411.  
  412.   : CLOSEDOWN
  413.  
  414.   FREE_COPPER
  415.   FREE_SLICECONTROL
  416.   FREE_DISPLAY
  417.   FREE_IMAGERY
  418.   FREE_RASINFO
  419.   FREE_DSLICES
  420.   RESETERROR"
  421.   ;
  422.  
  423.   LATESTCFA (CLOSEDOWN) !
  424.  
  425.   : TestDisplay          \ Start of program
  426.  
  427.   SCRCLR
  428.  
  429.   CR
  430.   ."        **********************************************************"
  431.   CR        6 FPENSET
  432.   ."                SINGLE PLAYFIELD WITH USER COPPERLIST DEMO"
  433.   CR        1 FPENSET
  434.   ."        **********************************************************"
  435.   CR
  436.   CR
  437.   ."        This code demonstrates how to create a single playfield"
  438.   CR
  439.   ."        display with a user copperlist displaying colour bars."
  440.   CR
  441.   CR
  442.   ."        This code builds upon the following Demos:"
  443.   CR
  444.   CR
  445.   ."        Demo1_SinglePF.src"
  446.   CR
  447.   CR
  448.   ."        This code is then expanded in the following Demos:"
  449.   CR
  450.   CR
  451.   ."        Demo3_SimpleSprite.src"
  452.   CR
  453.   ."        Demo4_MultiSprites.src"
  454.   CR
  455.   ."        Demo5_MultiSptCollide.src"
  456.   CR
  457.   ."        Demo6_SimpleAnim.src"
  458.   CR
  459.   ."        Demo7_MultiAnim.src"
  460.   CR
  461.   CR
  462.   ."        **********************************************************"
  463.   CR 6 FPENSET
  464.   ."                  Press <Space> or <L-Mouse> to see Demo          "
  465.   CR 1 FPENSET
  466.   ."        **********************************************************"
  467.   CR
  468.  
  469.   WAITSPACE
  470.  
  471.   SCRCLR
  472.  
  473.   ERROR1 SETERROR"       \ Redirect system errors to our routine ERROR1
  474.  
  475.   CREATE_DSLICES
  476.   CREATE_RASINFO
  477.   CREATE_IMAGERY
  478.   CREATE_DISPLAY
  479.   CREATE_SLICECONTROL
  480.   CREATE_COPPER
  481.  
  482.   HeliOS_On
  483.  
  484.   1 FrameRate !L
  485.  
  486.   Display1 SHOWDISPLAY
  487.  
  488.   WAITSPACE
  489.  
  490.   HeliOS_Off
  491.  
  492.   CLOSEDOWN
  493.   ;
  494.  
  495.   TestDisplay
  496.